package com.vhall.component.framework.oss.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @author shimingming
 * @since 2023/9/20 18:36
 */
@Getter
@AllArgsConstructor
public enum GuoXinOssUrlEnum {

    MANAGEMENT("live.web.guosen.com.cn", "https://live.web.guosen.com.cn/gsoss", "管理侧"),

    CLIENT("gslive.guosen.com.cn/live", "https://gslive.guosen.com.cn/gsoss", "客户侧"),


    ;

    /**
     * 前端请求的生产域名
     */
    private String webDomain;

    /**
     * 对象存储的域名
     */
    private String ossDomain;

    /**
     * 中文描述
     */
    private String desc;


    /**
     * 判断是否是生产环境，如果是生产，统一返回客户端域名
     *
     * @param requestUrl
     * @return
     */
    public static String prodJudgeAndReturnClientDomain(String requestUrl) {
        for (GuoXinOssUrlEnum template : GuoXinOssUrlEnum.values()) {
            if (requestUrl.contains(template.getWebDomain())) {
                return CLIENT.getOssDomain();
            }
        }
        return null;
    }

    public static String getOssDomain(String requestUrl) {
        for (GuoXinOssUrlEnum template : GuoXinOssUrlEnum.values()) {
            if (requestUrl.contains(template.getWebDomain())) {
                return template.ossDomain;
            }
        }
        return null;
    }

    public static GuoXinOssUrlEnum parse(String value) {
        for (GuoXinOssUrlEnum type : GuoXinOssUrlEnum.values()) {
            if (type.getWebDomain().equals(value)) {
                return type;
            }
        }
        return null;
    }
}
